set encoding=utf-8
syntax enable
filetype plugin indent on
syntax on
set autoindent
set expandtab  "expand tabs to space essential in python"
set ignorecase smartcase
set incsearch
set hlsearch
set paste
set ts=4  
set softtabstop=4 
set shiftwidth=4
set expandtab  
set nocompatible
set ruler 
set number relativenumber  " Hybrid line number on 
set backspace=indent,eol,start

"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
" Nerd Tree 使用 ctrl+n 配置
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    nnoremap <C-n> :NERDTreeToggle<CR>
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
" ctags -f ~/.tags -R -I __weak_alias /usr/include
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    set tags+=~/.tags 
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
"  Enable vim-powerline"
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
        let g:airline_powerline_fonts = 1 

"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
"  Enable Rainbow"
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
        let g:rainbow_active = 1
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
"   cppman enable"
    let g:cppman_open_mode = "vertical"
    autocmd FileType c,cpp setlocal keywordprg=:Cppman
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    set directory=$HOME/.vim/swap/ " 设置swap文件的目录,使用前mkdir swap
    set undofile
    set undodir=$HOME/.vim/undodir 

" enable auto format
        nnoremap <F6> :Autoformat<CR>
        let g:autoformat_autoindent = 0
        let g:autoformat_retab = 0
        let g:autoformat_remove_trailing_spaces = 0
" special setting for python
        au Filetype python set textwidth=80
        au Filetype python set expandtab
        au Filetype python set fileformat=unix
        autocmd Filetype python set foldmethod=indent
        autocmd Filetype python set foldlevel=99
"" 彩虹括号`
"RainbowParenthesesToggle
    let g:rainbow_conf = {
    \   'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick'],
    \   'ctermfgs': ['lightblue', 'lightyellow', 'lightcyan', 'lightmagenta'],
    \   'operators': '_,_',
    \   'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/{/ end=/}/ fold'],
    \   'separately': {
    \       '*': {},
    \       'tex': {
    \           'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/'],
    \       },
    \       'lisp': {
    \           'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick', 'darkorchid3'],
    \       },
    \       'vim': {
    \           'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/', 'start=/{/ end=/}/ fold', 'start=/(/ end=/)/ containedin=vimFuncBody', 'start=/\[/ end=/\]/ containedin=vimFuncBody', 'start=/{/ end=/}/ fold containedin=vimFuncBody'],
    \       },
    \       'html': {
    \           'parentheses': ['start=/\v\<((area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)[ >])@!\z([-_:a-zA-Z0-9]+)(\s+[-_:a-zA-Z0-9]+(\=("[^"]*"|'."'".'[^'."'".']*'."'".'|[^ '."'".'"><=`]*))?)*\>/ end=#</\z1># fold'],
    \       },
    \       'css': 0,
    \   }
    \}

" 改变esc的键盘映射
    inoremap <C-[> <ESC>
" 使用<ctrl> +hjkl在窗口之间跳转
    nnoremap <C-J> <C-W><C-J>
    nnoremap <C-K> <C-W><C-K>
    nnoremap <C-L> <C-W><C-L>
    nnoremap <C-H> <C-W><C-H>
" 括号自动补全
    inoremap ( ()<ESC>i  "设置（自动补全
    inoremap [ []<ESC>i  "设置[自动补全
    "inoremap { {}<ESC>i  "设置{自动补全
    inoremap < <><ESC>i  "设置<自动补全
    inoremap ' ''<ESC>i  "设置'自动补全
    inoremap " ""<ESC>i  "设置"自动补全
let g:scheme_executable = "mit-scheme"

"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
"    VIM-Youcompleteme 配置
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
"设置自动补全的高度
    set pumheight=10  

"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
"   enable auto compile
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
map <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
        exec "w"
        if &filetype == 'c'
                exec "!clang % -o %<"
                exec "!time ./%<"
        elseif &filetype == 'cpp'
                exec "!clang++ % -o %<"
                exec "!time ./%<"
        elseif &filetype == 'rust'
                exec "!cargo run"
        elseif &filetype == 'java'
                exec "!javac %"
                exec "!time java %<"
        elseif &filetype == 'sh'
                :!time bash %
        elseif &filetype == 'python'
                exec "!clear"
                exec "!time python3 %"
        endif
endfunc
